<template>
  <div>
    <el-container>
      <el-header>
        <el-link @click="dl()" v-if="user == undefined" type="success"
          >登录</el-link
        >
        <span v-else>{{ user.department.dname }}-{{ user.name }}</span>
        /&emsp;<el-link @click="zx()" type="danger">注销</el-link>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <div>
            <el-col>
              <el-menu
                default-active="2"
                class="el-menu-vertical-demo"
                @open="handleOpen"
                @close="handleClose"
                @select="handleSelect"
                background-color="#545c64"
                text-color="#fff"
                active-text-color="#ffd04b"
              >
                <div v-for="m in menulist" :key="m.mid">
                  <el-submenu v-if="m.mstate == 0" :index="m.mpath">
                    <template slot="title">
                      <i :class="m.micon"></i>
                      <span>{{ m.mname }}</span>
                    </template>
                    <el-menu-item
                      v-for="item in m.children"
                      :key="item.mid"
                      :index="item.mpath"
                    >
                      <i :class="item.micon"></i>
                      <span slot="title">{{ item.mname }}</span>
                    </el-menu-item>
                  </el-submenu>
                  <el-menu-item v-else :index="m.mpath">
                    <i :class="item.micon"></i>
                    <span slot="title">{{ item.mname }}</span>
                  </el-menu-item>
                </div>
              </el-menu>
            </el-col>
          </div>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      user: JSON.parse(sessionStorage.getItem("user")),
      menulist: [],
    };
  },
  mounted() {
    var my = this;
    this.$axios
      .get("http://localhost:5230/api/item1/Getmenu?uid=" + my.user.uid)
      .then(function (s) {
        my.menulist = s.data.mod;
      });
  },
  methods: {
    dl() {
      this.$router.push("/Login");
    },
    zx() {
      sessionStorage.removeItem("user");
      this.$router.push("/Login");
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
      this.$router.push(key);
    },
  },
};
</script>



<style>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
